#!/bin/bash
# 汉字转unicode 
# 2016-12-28

test -z $1 && echo "null" && exit 0
string=$1
index=0
while [ ! -z ${string:index:1} ]; do
    #十进制数值
    dec=`printf "%u\n" \'${string:index:1}`
    #echo $dec 大于键盘符号的，就转码为unicode
    if [ $dec -lt 255  ]; then
            printf ${string:index:1}
    else
            printf "\\\\u%x" \'${string:index:1}
    fi
    let index++
done
printf "\n"